package xyz.jangle.io;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;

public class RWMain {

	public static void main(String[] args) {
//		try {
//			test();
//		} catch (Exception e) {
//			e.printStackTrace();
//		}

		try (//Reader reader = new InputStreamReader(new FileInputStream("D:/桌面/huhongjing.txt"));
				Reader reader = new FileReader("D:/桌面/huhongjing.txt");
				Writer writer = new FileWriter("D:/桌面/huhongjing2.txt")) {

			char[] buff = new char[8];
			int length = 0;
			while ((length = reader.read(buff)) != -1) {
				System.out.print(new String(buff, 0, length));
				writer.write(buff, 0, length);
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}
	
	//先写后读
	@SuppressWarnings("unused")
	private static void test() throws Exception {
		FileWriter writer = new FileWriter("test2.txt");
		
		char[] chars = {'A','B','C'};
//		for (int i = 0; i < chars.length; i++) {
//			writer.write(chars[i]);
//		}
		writer.write(chars);
		writer.flush();
		writer.close();
		
		FileReader reader = new FileReader("test2.txt");
		char[] cs = new char[100];
		int read = reader.read(cs);
		System.out.println(new String(cs, 0, read));
		reader.close();
		
	}

}
